<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
defined( '_AppBackMiage' ) or die( 'Restricted access' );
include_once (DS."backoffice/include/header.php");
?>
<div id="wrapper">
    <div id="content">
        <div id="rightnow">
            <h3 class="reallynow">
                <span>Liste des Dates</span>
                <a href="<?php echo URL; ?>index.php?m=admin_dates_add" class="add">Ajouter une date</a>
                <br />
            </h3>
            <p class="youhave">
            <?php
            $dates = Date::getList();

            $count = Date::globalCount();

            if (!empty($dates))
            {
            ?>
                <table width="100%">
                    <thead>
                        <tr>
                            <th width="40px">Promo</th>
                            <th>Titre</th>
                            <th width="150px">Valeur</th>
                            <th width="60px">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    foreach ($dates as $i=>$date)
                    {
                        $editURL = URL . "/index.php?m=admin_dates_edit&uid=" . $date->IdDate;
                        $deleteURL = "#";
                        ?>
                        <tr>
                            <td><?php $promo = new Promo($date->IdPromo); echo stripcslashes($promo->getNom()); ?></td>
                            <td><?php echo stripcslashes($date->TitreDate); ?></td>
                            <td>
                                <?php
                                    switch($date->TypeDate)
                                    {
                                        case 0:
                                            echo date('d/m/Y', $date->ValeurDate);
                                            break;
                                        case 1:
                                            $timestamp = intval($date->ValeurDate);
                                            $time = Tools::transformTimestampToDuree($timestamp);
                                            $mois = $time['mois'];
                                            $jours = $time['jours'];
                                            echo "$mois mois";
                                            if( $jours >= 14 && $jours <= 16)
                                            {
                                                echo " et demi";
                                            }
                                            elseif( $jours == 0 )
                                            {

                                            }
                                            else
                                            {
                                                echo "  $jours jours";
                                            }
                                            break;
                                        case 2:
                                            echo stripcslashes($date->ValeurDate);
                                            break;
                                    }
                                ?>
                            </td>
                            <td>
                                <a href="<?php echo $editURL; ?>">
                                    <img src="<?php echo STYLEBK; ?>img/icons/cog.png" title="Modifier la date" width="16" height="16" />
                                </a>
                                <a href="<?php echo $deleteURL; ?>">
                                    <img src="<?php echo STYLEBK; ?>img/icons/page_white_delete.png" title="Supprimer la date" width="16" height="16" />
                                </a>
                            </td>
                        </tr>
                    <?php
                    }
                    ?>
                    </tbody>
                </table>
            <?php
            }
            else
            {
                echo 'Aucune';
            }
            ?>
            </p>
        </div>
    </div>
<?php
include_once (DS."backoffice/include/sidebar.php");
include_once (DS."backoffice/include/footer.php");
?>
